package com.cx.base.rx;


import com.jakewharton.rxrelay2.PublishRelay;
import com.jakewharton.rxrelay2.Relay;

import io.reactivex.Observable;

/**
 * 事件总线
 */

public class RxBus {
    private final Relay<Object> mBus;
    private static final RxBus bus = new RxBus();

    private RxBus() {
        mBus = PublishRelay.create().toSerialized();
    }


    public static RxBus getInstance() {
        return bus;
    }


    public void post(Object obj) {
        mBus.accept(obj);
    }

    public <T> Observable<T> toObservable(Class<T> tClass) {
        return mBus.ofType(tClass);
    }

    public Observable<Object> toObservable() {
        return mBus;
    }

    public boolean hasObservers() {
        return mBus.hasObservers();
    }


}
